import  os
"""
功能：使用OS调用系统函数实现Docker的管理
创建时间：2020年6月14日12:54:01
作者：信|仰
博客：https://blog.csdn.net/qq_36154886
"""
class images():
    def lists(self):
        cmd = "docker images"
        os.system(cmd)
    def info(self,image):
        cmd_info = "docker inspect " + image
        os.system(cmd_info)
    def rmi(self,image):
        cmd_del = "docker rmi " + image
        os.system(cmd_del)
    def pull(self,name):
        cmd_pull = "docker pull " + name
        os.system(cmd_pull)
    def build(self, name, path):
        print("镜像构建")
    def save(self, ID, name, path):
        print("保存镜像")
    def load(self, path, name, ver):
        print("上传镜像")
class containers():
    def status_all(self):
        cmd_show_all = "docker ps -a"
        os.system(cmd_show_all)
    def status_ps(self):
        cmd_show_ps = "docker ps"
        os.system(cmd_show_ps)
    def status_exited(self):
        cmd_show_exit = "docker ps -a --filter 'exited=0'"
        os.system(cmd_show_exit)
    def status_runing(self):
        cmd_show_runing = "docker ps --filter status=running"
        os.system(cmd_show_runing)
    def status_paused(self):
        cmd_show_paused = "docker ps --filter status=paused"
        os.system(cmd_show_paused)
    def info(self, image):
        cmd_info = "docker inspect " + image
        os.system(cmd_info)
    def rm(self, image):
        cmd_rm = "docker rm  " + image
        os.system(cmd_rm)
    def rm_f(self,image):
        cmd_rm_f = "docker rm -f " + image
        os.system(cmd_rm_f)
    def rm_all(self):
        cmd_rm_all = "docker rm -f `docker ps -qa"
        os.system(cmd_rm_all)
    def it(self, images, name=str(' '), custom=str(' '), port=str(' '), init_cmd=str(' '), link=str(' '), privileged=str(' ')):
        cmd_run = "docker run -ti "
        os.system(cmd_run)
    def it_rm(self, images, name, custom, port, init_cmd):
        if name:
            cmd = "docker run -ti --name " + name + " " + custom + " " + port + images + " " + init_cmd
        else:
            cmd = "docker run -ti " + " " + custom + " " + port + images + " " + init_cmd
        os.system(cmd)
    def it_privileged(self, images, name, custom, port, init_cmd):
        if name:
            cmd_run = "docker run -tid --privileged=true --name "
    def tid(self, images, name, custom, init_cmd):
        cmd_run_tid = "docker run -tid --name " + name + " " + custom + " " + images + " " + init_cmd
        print("启动命令:", cmd_run_tid)
        os.system(cmd_run_tid)
    def stop(selfs, id_name):
        cmd = "docker stop " + id_name
        os.system(cmd)
    def start(self, id_name):
        cmd = "docker start " + id_name
        os.system(cmd)
    def restart(self, id_name):
        cmd = "docker restart " + id_name
        os.system(cmd)
    def kill(self, id_name):
        cmd = "docker kill -s KILL " + id_name
        os.system(cmd)
    def pause(self, id_name):
        cmd = "docker pause " + id_name
        os.system(cmd)
    def unpause(self, id_name):
        cmd = "docker unpause " + id_name
        os.system(cmd)
    def create(self, id_name):
        cmd = "docker create " + id_name
        os.system(cmd)
    def top(self, id_name):
        cmd = "docker top " + id_name
        os.system(cmd)
    def attch(self, id_name):
        cmd = "docker attch " + id_name
        os.system(cmd)
    def events(self, id_name):
        cmd = "docker events " + id_name
        os.system(cmd)
    def events_f(self, f, id_name):
        cmd = "docker events -f " + f + id_name
        os.system(cmd)
    def events_f_s(self, f, s, u, id_name):
        cmd = "docker events " + "-f" + f + "--since=" + s + "--until" + u + id_name
        os.system(cmd)
    def logs_since(self, id_name):
        cmd = "docker logs "
class network():
    def add(self, name, types, subnet):
        print(name, types, subnet)
    def delete(self, name):
        print("deleteing:", name)
    def info(self, name):
        print("show network info:", name)


